package com.mall.admin.controller;

import com.mall.admin.service.SmsCouponService;
import com.mall.commons.utils.PageResult;
import com.mall.commons.utils.R;
import com.mall.dto.CouponDto;
import com.mall.vo.CouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/coupon")
public class SmsCouponController {

    @Autowired
    private SmsCouponService smsCouponService;

    //添加优惠券
    @PostMapping("/create")
    public R addCoupon(@RequestBody CouponDto dto){
        smsCouponService.addCoupon(dto);
        return R.success("添加优惠券",null);
    }

    //删除优惠券
    @PostMapping("/delete/{id}")
    public R deleteCoupon(@PathVariable Long id){
        smsCouponService.deleteCoupon(id);
        return R.success("删除优惠券",null);
    }

    //根据优惠券名称和类型分页获取优惠券列表
    @GetMapping("/list")
    public R list(String name,Integer pageNum,Integer pageSize,Integer type){
        PageResult pageResult = smsCouponService.list(name,pageNum,pageSize,type);
        return R.success("分页展示优惠券列表",pageResult);
    }

    //修改优惠券
    @PostMapping("/update/{id}")
    public R update(@PathVariable Long id,@RequestBody CouponDto dto){
        smsCouponService.update(id,dto);
        return R.success("修改优惠券",null);
    }

    //获取单个优惠券的详细信息
    @GetMapping("/{id}")
    public R findCoupon(@PathVariable Long id){
        CouponVo vo = smsCouponService.findCoupon(id);
        return R.success("获取单个优惠券",vo);
    }


}
